package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.AttendPunchDailyReportAddDTO;
import org.jsola.hr.dto.AttendPunchDailyReportUpdateDTO;
import org.jsola.hr.entity.AttendPunchDailyReportDO;
import org.jsola.hr.query.AttendPunchDailyReportQuery;
import org.jsola.hr.service.IAttendPunchDailyReportService;
import org.jsola.hr.vo.AttendPunchDailyReportVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class AttendPunchDailyReportTestHelper extends BaseTestHelper {
    
    @Autowired
    private IAttendPunchDailyReportService attendPunchDailyReportService;

    /**
     * 生成add测试数据
     * @return AttendPunchDailyReportAddDTO
     */
    public AttendPunchDailyReportAddDTO getAttendPunchDailyReportAddDTO(){
        AttendPunchDailyReportAddDTO attendPunchDailyReportAddDTO = new AttendPunchDailyReportAddDTO();
        attendPunchDailyReportAddDTO.setDailySummaryId(getRandomValue("varchar",32));
        attendPunchDailyReportAddDTO.setCompanyId(getRandomValue("varchar",32));
        attendPunchDailyReportAddDTO.setCompanyName(getRandomValue("varchar",100));
        attendPunchDailyReportAddDTO.setDeptId(getRandomValue("varchar",32));
        attendPunchDailyReportAddDTO.setDeptName(getRandomValue("varchar",100));
        attendPunchDailyReportAddDTO.setAttendPlanId(getRandomValue("varchar",32));
        attendPunchDailyReportAddDTO.setEmpInfoId(getRandomValue("varchar",32));
        attendPunchDailyReportAddDTO.setEmpInfoName(getRandomValue("varchar",50));
        attendPunchDailyReportAddDTO.setYearly(getRandomValue("varchar",10));
        attendPunchDailyReportAddDTO.setMonthly(getRandomValue("varchar",10));
        attendPunchDailyReportAddDTO.setDaily(getRandomValue("varchar",10));
        attendPunchDailyReportAddDTO.setSignInLocation(getRandomValue("varchar",255));
        attendPunchDailyReportAddDTO.setSignOutLocation(getRandomValue("varchar",255));
        attendPunchDailyReportAddDTO.setIsGoOut(SafeKit.getInteger(getRandomValue("tinyint",4)));
        attendPunchDailyReportAddDTO.setGoOutLocation(getRandomValue("varchar",255));
        attendPunchDailyReportAddDTO.setGoOutHours(SafeKit.getBigDecimal(getRandomValue("decimal",5)));
        attendPunchDailyReportAddDTO.setIsUsed(SafeKit.getInteger(getRandomValue("tinyint",4)));
        attendPunchDailyReportAddDTO.setAttendStatus(SafeKit.getInteger(getRandomValue("int",11)));
        attendPunchDailyReportAddDTO.setOvertimeHours(SafeKit.getBigDecimal(getRandomValue("decimal",10)));
        attendPunchDailyReportAddDTO.setEarliestTime(getRandomValue("varchar",10));
        attendPunchDailyReportAddDTO.setLatestTime(getRandomValue("varchar",10));
        attendPunchDailyReportAddDTO.setPunchCounts(SafeKit.getInteger(getRandomValue("int",11)));
        attendPunchDailyReportAddDTO.setWorkTimeMinute(SafeKit.getInteger(getRandomValue("int",11)));
        attendPunchDailyReportAddDTO.setHisAttendStatus(SafeKit.getInteger(getRandomValue("int",11)));
        attendPunchDailyReportAddDTO.setOvertimeStatus(SafeKit.getInteger(getRandomValue("int",11)));
        attendPunchDailyReportAddDTO.setMinutes(SafeKit.getInteger(getRandomValue("int",11)));
        return attendPunchDailyReportAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AttendPunchDailyReportUpdateDTO
     */
    public AttendPunchDailyReportUpdateDTO getAttendPunchDailyReportUpdateDTO(AttendPunchDailyReportVO attendPunchDailyReportVO){
        return attendPunchDailyReportService.selectDOById(attendPunchDailyReportVO.getId(), SITE_ID).to(AttendPunchDailyReportUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AttendPunchDailyReportQuery
     */
    public AttendPunchDailyReportQuery getAttendPunchDailyReportQuery() {
        AttendPunchDailyReportQuery attendPunchDailyReportQuery = new AttendPunchDailyReportQuery();
        List<AttendPunchDailyReportDO> attendPunchDailyReportDOList = attendPunchDailyReportService.list(new AttendPunchDailyReportDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(attendPunchDailyReportDOList)) {
            AttendPunchDailyReportDO attendPunchDailyReportDO = attendPunchDailyReportDOList.get(0);
            attendPunchDailyReportQuery = attendPunchDailyReportDO.to(AttendPunchDailyReportQuery.class);
            if (attendPunchDailyReportDO.getGoOutHours() != null) {
                attendPunchDailyReportQuery.setGoOutHoursStart(attendPunchDailyReportDO.getGoOutHours().subtract(new BigDecimal(1)));
                attendPunchDailyReportQuery.setGoOutHoursEnd(attendPunchDailyReportDO.getGoOutHours().add(new BigDecimal(1)));
            }
            if (attendPunchDailyReportDO.getOvertimeHours() != null) {
                attendPunchDailyReportQuery.setOvertimeHoursStart(attendPunchDailyReportDO.getOvertimeHours().subtract(new BigDecimal(1)));
                attendPunchDailyReportQuery.setOvertimeHoursEnd(attendPunchDailyReportDO.getOvertimeHours().add(new BigDecimal(1)));
            }
        }
        return attendPunchDailyReportQuery;
    }

    /**
     * 保存示例
     * @return AttendPunchDailyReportVO
     */
    public AttendPunchDailyReportVO saveAttendPunchDailyReportExample(){
        AttendPunchDailyReportAddDTO addDTO = this.getAttendPunchDailyReportAddDTO();
        AttendPunchDailyReportVO attendPunchDailyReportVO = attendPunchDailyReportService.save(addDTO,buildTokenUser());
        return attendPunchDailyReportVO;
    }


}

